package cn.kgc.crowdfundingadmin2.service;

import cn.kgc.crowdfundingadmin2.mapper.AuthMapper;
import cn.kgc.crowdfundingadmin2.pojo.Auth;
import cn.kgc.crowdfundingadmin2.pojo.Role;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AuthServiceImpl implements AuthService {

    @Resource
    AuthMapper authMapper;

    @Override
    public List<Auth> getAllAuth() {
        return authMapper.selectByExample(null);
    }

    @Override
    public List<Integer> getAssignedAuthIdList(Integer roleId) {
        return authMapper.getAssignedAuthIdList(roleId);
    }

    @Override
    public void updateRelationShipBetweenRoleAndAuth(Map<String, List<Integer>> assignDataMap) {
        Integer roleId = assignDataMap.get("roleIdList").get(0);
        authMapper.deleteRelationship(roleId);

        authMapper.insertRelationship(roleId,assignDataMap.get("authIdList"));
    }
}
